﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FirmaTransportowa
{
    public partial class DispatcherPanel : Form
    {
        SqlConnection dbConnection;
        int userID = 0;
        static DispatcherAddNewTransport dispatcherAddNewTransport = new DispatcherAddNewTransport();
        static DispatcherTransportsList dispatcherTransportsList = new DispatcherTransportsList();
        static DispatcherPackagesList dispatcherPackagesList = new DispatcherPackagesList();

        public DispatcherPanel(int id)
        {
            SqlConnector connection = new SqlConnector();
            dbConnection = connection.getInstance();
            try
            {
                dbConnection.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            InitializeComponent();
            userID = id;
            SqlCommand selectName = new SqlCommand("SELECT w.name, w.surname FROM Workers w WHERE w.worker_ID = (SELECT u.worker_id FROM Users u WHERE u.user_ID = " + userID + ")", dbConnection);
            SqlDataReader nameReader = null;
            nameReader = selectName.ExecuteReader();
            nameReader.Read();
            dispatcherName.Text = nameReader["name"].ToString() + " " + nameReader["surname"].ToString();
            DateTime dateTime = DateTime.Now;
            dispatcherDateAndTime.Text = dateTime.ToString();
            nameReader.Close();
        }

        private void edytujToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void transportToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void zakoToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void DispatcherPanel_Load(object sender, EventArgs e)
        {
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        protected override void OnFormClosing(FormClosingEventArgs e) {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                Application.Exit();
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void checkedListBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void progressBar1_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void nowyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (dispatcherAddNewTransport.IsDisposed) dispatcherAddNewTransport = new DispatcherAddNewTransport();
            dispatcherAddNewTransport.setUserID(userID);
            dispatcherAddNewTransport.Show();
        }

        private void DispatcherPanel_Shown(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (dispatcherTransportsList.IsDisposed) dispatcherTransportsList = new DispatcherTransportsList();
            dispatcherTransportsList.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            dispatcherDateAndTime.Text = DateTime.Now.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dispatcherPackagesList.IsDisposed) dispatcherPackagesList = new DispatcherPackagesList();
            dispatcherPackagesList.Show();
        }
    }
}
